<template>
  <div class="container">
    <baleTable :tableData="tableData" :tableHead="tableHead" :isSearch="true" :tableLoading="tableLoading" :page="page"
      @pageSizeChange="pageSizeChange" @handleCurrentChange="handleCurrentChange" @searchMethods="searchMethods"
      @tableSortChange="tableSortChange" @handleRowClick="handleRowClick" ref="baleTable">
      <template #headLeft>
        <el-button size="small" type="primary" @click="prescribingClick('')">添加</el-button>
      </template>
      <template #caozuo="{ scope }">
        <el-button type="primary" size="mini" @click="prescribingClick(scope.row)">编辑</el-button>
        <el-button type="danger" size="mini" @click="delTem(scope.row)">删除</el-button>
      </template>
      <template #medical="{ scope }">
        <div class="mb5" v-for="item in JSON.parse(scope.row.medical)" :key="item.id">
          <el-popover trigger="hover" placement="top">
            <p>单价: {{item.price }}</p>
            <p>药品规格: {{item.size }}</p>
           <!--  <p>频率(次): {{item.doseFrequency }}</p>
            <p>用药天数(天): {{item.days }}</p> -->
            <p>剂量: {{item.dosage }}</p>
          <!--   <p>注意事项: {{item.precautions }}</p> -->
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ item.name }}</el-tag>
            </div>
          </el-popover>
        </div>
      </template>
    </baleTable>
    <prescribing ref="prescribing" @refresh="getTableData()" />
  </div>
</template>

<script>
import prescribing from "./component/prescribing.vue"
import { ApiGetAdviceTemplate, ApidelAdviceTemplate } from "@a/index";
import { tableHead } from "./config";
export default {
  components: { prescribing },
  data() {
    return {
      tableHead,
      tableData: [],
      page: {
        page: 1,
        size: 25,
        total: 0,
      },
      tableLoading: false,
      searchParams: {},
      sortParams: {},
      editFormVisible: false,
      btnLoading: false,
    };
  },
  mounted() {
    this.getTableData();
  },
  methods: {
    //开处方
    prescribingClick(val) {
      this.$refs.prescribing.show(val)
    },
    getTableData(params = {}) {
      let postParams = {
        ...params,
        ...this.searchParams,
        ...this.sortParams,
        ...this.page,
      };
      this.tableLoading = true;
      ApiGetAdviceTemplate(postParams).then((res) => {
        let { data, page } = res;
        this.tableData = data;
        this.page.total = page.total;

        this.tableLoading = false;
      });
    },
    searchMethods(params) {
      this.searchParams = {};
      this.page.page = 1;
      this.searchParams = params;
      this.getTableData();
    },
    pageSizeChange(val) {
      this.page.size = val;
      this.getTableData();
    },
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTableData();
    },
    tableSortChange(params) {
      if (params.sort_str) {
        this.sortParams = { ...this.sortParams, ...params };
      } else {
        delete this.sortParams.sort_str;
        delete this.sortParams.sort_order;
      }
      this.page.page = 1;
      this.getTableData();
    },
    handleRowClick(params) { },
    delTem(val) {
      this.$confirm("是否删除该模板?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        center: true,
        type: "warning",
      })
        .then((res) => {
          ApidelAdviceTemplate(val.id).then((res) => {
            this.$message.success("操作成功！");
            this.getTableData();
          });
        })
        .catch((err) => {

        });
    },
  },
  filters: {},
};
</script>

<style lang="less" scoped>
</style>
